package com.lzq.leetcode.hoot100;

import java.util.HashSet;
import java.util.Set;

public class s128 {

    public int longestConsecutive(int[] nums) {

        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        int max = Integer.MIN_VALUE;
        for (int num : set) {
            if (!set.contains(num-1)) {
                int cur = 1;
                while (set.contains(num + cur)) {
                    cur++;
                }

                max = Math.max(max, cur);
            }
        }

        return max;

    }
}
